<!--
*  2021-03-15
*  织造 / 验布  流程
-->
<template>
  <div id="app" class="checkCloth" tabindex="-1" ref="tabDiv">
    <!-- 头部导航 -->
    <div class="checkCloth——nav">
      <van-nav-bar
        left-arrow
        :right-text="'总计：' + getFloat(totalLength, 1) + '米'"
      >
        <template #title>
          <span style="margin-left: 130px; margin-right: 50px">{{
            craftNo + (craftNo ? "织机验布" : "验布")
          }}</span>
          <span v-show="designSeqNo">{{ "匹号:" + designSeqNo }}</span>
        </template>
        <template #left>
          <div>
            <van-button icon="arrow-left" type="primary" @click="onClickLeft"
              >返回扫码</van-button
            >
            <van-button type="danger" @click="onClickReconnection"
              >重新连接</van-button
            >
            <van-button type="danger" @click="onClickSetRice"
              >计米器归零</van-button
            >
          </div>
        </template>
      </van-nav-bar>
      <div class="checkCloth——nav_weight">
        <span>重量：</span>
        <van-field
          v-model="currWeight"
          type="tel"
          @focus="currWeight = ''"
        ></van-field>
      </div>
    </div>

    <!-- 长度详情 -->
    <div class="checkCloth-wrapper">
      <div class="checkCloth-wrapper__left">
        <better-scroll
          class="public-scroll"
          :data="tableData"
          :totalPage="totalPage"
        >
          <van-cell-group>
            <van-cell
              v-for="(data, index) in tableData"
              :key="index"
              :title="index + 1 + '、' + ' ' + data.no"
            >
              <template #default>
                <van-field
                  v-model="data.originalValue"
                  type="tel"
                  center
                  clearable
                  placeholder="请输入长度"
                  @input="onClickInput"
                >
                  <template #button>
                    <van-button
                      size="small"
                      type="primary"
                      @click="onClickGetTable(index)"
                      v-show="index == tableData.length - 1"
                      >手动获取长度</van-button
                    >
                  </template>
                </van-field>
              </template>
              <template #right-icon>
                <van-button type="danger" size="small" @click="onDelete(index)"
                  >删除</van-button
                >
              </template>
            </van-cell>
            <van-cell-group class="checkCloth-wrapper__right-btn">
              <van-button
                v-for="(btn, index) in loginBtn"
                :key="index"
                :color="btn.color"
                @click="onClickScanBtn(btn)"
              >
                {{ btn.realName }}
              </van-button>
            </van-cell-group>
          </van-cell-group>
        </better-scroll>
        <van-cell-group class="checkCloth-btn">
          <van-button @click="userClickBtn">
            {{ printStatus ? "重新打印" : "保存" }}
          </van-button>
        </van-cell-group>
      </div>
      <div class="checkCloth-wrapper__right">
        <van-cell title="下机门幅">
          <template #default>
            <van-field
              v-model="width"
              placeholder="下机门幅"
              type="tel"
            ></van-field>
          </template>
        </van-cell>
        <van-cell title="克重参考值">
          <template #default>
            <van-field
              v-model="referenceMiWeight"
              placeholder="克重参考值"
              type="tel"
              readonly
              @click="show4ChangeMiWeight = true"
            ></van-field>
          </template>
        </van-cell>
        <van-cell title="刻盘克重">
          <template #default>
            <van-field
                v-model="miWeight"
                placeholder="刻盘克重"
                type="tel"
                readonly
            ></van-field>
          </template>
        </van-cell>
        <van-cell title="设计克重">
          <template #default>
            <van-field
                v-model="designMiWeight"
                placeholder="设计克重"
                type="tel"
                readonly
            ></van-field>
          </template>
        </van-cell>
        <div style="height: 50vh;overflow: auto">
          <div style="display: flex;" v-for="btn in flaw.btnArr">
            <van-button style="flex: 0 0 10vw;margin-bottom: 1vh;font-size: 1.5rem" :color="btn.color" @click="addFlawFn(btn)">{{ btn.text }}</van-button>
            <div style="flex: 1; margin-left:1vw; display: flex; flex-wrap: wrap">
              <van-tag style="margin-right: 1vw;margin-bottom: 1vh;height: 3.5vh;" closeable size="large" type="primary" v-for="tag in flaw.data.filter(t => t.flaw == btn.text)" @close="delFlawFn(tag)">{{ tag.pos }}</van-tag>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 重新扫码 -->
    <van-dialog
      className="login-dialog"
      v-model="isLogin"
      title="确认重新扫码？"
      show-cancel-button
      confirm-button-text="重新扫码"
      @confirm="onClickBack"
    >
      <span>扫码后需重新登陆</span>
    </van-dialog>

    <!-- 扫码获取重量 -->
    <van-dialog
      className="login-dialog"
      v-model="scanStatus"
      title="提示"
      show-cancel-button
      :confirm-button-text="'确认' + '(' + getFloat(currWeight, 1) + ')'"
      @confirm="onGetNextInfo"
    >
      <span v-if="(referenceMiWeight - getFloat(currWeight * 1000 / totalLength, 1)) > errorMiWeight" style="color: #e4393c">克重({{ getFloat(currWeight * 1000 / totalLength, 1) }})太轻<br/>请核对重量是否正确</span>
      <span v-else-if="(getFloat(currWeight * 1000 / totalLength, 1) - referenceMiWeight) > errorMiWeight" style="color: #67c23a">克重({{ getFloat(currWeight * 1000 / totalLength, 1) }})太重<br/>请核对重量是否正确</span>
      <span v-else>核对重量,克重({{ getFloat(currWeight * 1000 / totalLength, 1) }})是否正确</span>
    </van-dialog>

    <!-- 修改刻盘米克重 -->
    <van-dialog v-model="show4ChangeMiWeight" title="调整参考克重" show-cancel-button @confirm="scan4ChangeMiWeightFn" @cancel="show4ChangeMiWeight = false">
      <van-field clearable type="tel" placeholder="请输入调整后的克重" v-model="changedMiWeight" size="large" input-align="center"></van-field>
    </van-dialog>
    <audio ref="errMiWeightWarnAudio" :src="errMiWeightWarnAudioSrc"></audio>
  </div>
</template>

<script>
import { openWin, deepCopy, getFloat, randomStr } from "@/utils/index";
import { getInit, getTaskStep, getClothList, getLogin } from "@/api/login";
import {
  setWeight,
  getWeight,
  setScanTime,
  removeScanTime,
  getScanTime,
  setErrorWeight,
  getErrorWeight,
  setTableData,
  getTableData,
  removeTableData,
} from "@/utils/auth";
import {
  getConfirmStep,
  getTaskList,
  getNextInfo,
  getNextCommit,
  getWorkerInfo,
  changeMarkMiWeight,
} from "@/api/warping";
import dayjs from "dayjs";
import {loadFlawConfigData} from "@/api/flaws";
import {randomColor} from "@/utils/common";
import {SPLIT_BLANK, SPLIT_COLON, SPLIT_COMMA, SPLIT_SPACE} from "@/utils/enum";
import storage from 'good-storage'

export default {
  name: "CheckCloth",
  data() {
    return {
      value: "",
      tableData: [
        // {
        //   items: [
        //     [
        //       { label: "测试测试", originalValue: 15.55 },
        //       { label: "测试测试", originalValue: 15.55 },
        //     ],
        //     [{ label: "测试测试", originalValue: 15.55 }],
        //   ],
        // },
        // {
        //   items: [
        //     [
        //       { label: "测试测试", originalValue: 15.55 },
        //       { label: "测试测试", originalValue: 15.55 },
        //     ],
        //     [{ label: "测试测试", originalValue: 15.55 }],
        //   ],
        // },
      ],
      errorMiWeight: 30,
      items: [],
      defaultData: [],
      totalPage: 1,
      SPPClientArr: [],
      serveUUID: "00001101-0000-1000-8000-00805F9B34FB",
      show: false,
      address: "",
      pairedDevices: [], // 已配对设备
      length: "",
      resId: "",
      metreMac: "",
      totalLength: 0,
      isLogin: false,
      loading: false,
      code: "",
      lastTime: "",
      nextTime: "",
      lastCode: "",
      nextCode: "",
      scanStatus: false,
      params: {},
      printMac: "",
      repeatNum: 0,
      currIndex: 0,
      otherLenFlag: false,
      index: "",
      key: "",
      obtainStatus: false,
      btnArr: [],
      childIndex: 0,
      childValue: 0,
      btnIndex: 0,
      newArr: [],
      str: "",
      printStatus: false,
      pos: {},
      weight: 0,
      currWeight: '',
      totalWeight: 0,
      lastClickTime: 0,
      isWeight: false,
      loginBtn: [],
      width: "",
      craftNo: "",
      referenceMiWeight: "",    //克重参考值
      miWeight: "",    //刻盘克重
      designMiWeight: "",   //设计克重
      clickStatus: false,
      designSeqNo: "",

      /* 米克重 */
      scanOpt: 0,    //1-changeMiWeight; 2-passErrWeight
      craftId: 0,
      changedMiWeight: "",
      show4ChangeMiWeight: false,
      scan4ChangeMiWeightTimer: null,
      errMiWeightWarnAudioSrc: require("../../assets/audio/warn.wav"),

      /* 疵点 */
      flaw: {
        taskId: 0,
        curBtn: null,
        btnArr: [],
        data: [],
      }
    };
  },
  watch: {
    metreMac() {
      if (this.metreMac) {
        this.isEnabledBluetooth();
      } else {
        this.onGetInit();
      }
    },
    tableData: {
      handler() {
        this.totalLength = 0;
        this.tableData.forEach((item) => {
          this.totalLength += Number(item.originalValue) * 100;
        });
        this.totalLength = getFloat(this.totalLength / 100, 1);
        // 存储数据
        let filterArr = this.tableData.filter((item) => item.workerId !== "");
        if (filterArr.length != 0) {
          setTableData(this.tableData);
        }
      },
      deep: true,
    },
    SPPClientArr: {
      handler() {},
      deep: true,
    },
    obtainStatus() {
      const that = this;
      if (that.obtainStatus) {
        setTimeout(() => {
          let resultArr = [];
          if (that.SPPClientArr.length != 0) {
            resultArr = that.SPPClientArr.reduce(function (a, b) {
              return a.concat(b);
            });
            if (resultArr.length != 9 && resultArr.length != 8) {
              that.$toast.loading("重新获取中");
              that.sendDataSPP(this.checkHexStr("01 03 00 21 00 02 94 01"));
            }
          }
        }, 1500);
      }
    },
  },
  created() {
    const that = this;
    if (process.env.NODE_ENV === "production") {
      that.$nextTick(() => {
        that.init();
      });
    } else {
      window.apiready = () => {
        that.init();
      };
    }
  },
  methods: {
    getFloat,
    // 返回
    onClickLeft() {
      this.isLogin = true;
    },
    // 重新扫码
    onClickBack() {
      openWin("index");
    },
    // 打印初始化
    onGetInit() {
      this.printMac = "";
      this.metreMac = "";
      this.pos = {};
      const that = this;
      getInit({}, (res) => {
        let resultArr = eval("(" + res.propertyValue + ")");
        resultArr.forEach((item) => {
          if (item.type == "1") {
            that.printMac = item.mac;
            let posData = item.pos.split(",");
            that.pos = {
              x: Number(posData[0]),
              y: Number(posData[1]),
            };
          } else if (item.type == "2") {
            // console.log(item.mac);
            that.metreMac = item.mac;
          }
        });
      });
    },
    // 获取检查项
    onGetTableData() {
      const that = this;
      that.tableData = [];
      that.items = [];
      that.btnArr = [];
      getConfirmStep(
        {
          resUrl:
            process.env.VUE_APP_YARN_URL +
            that.params.nextResUrl +
            "/" +
            that.params.taskId,
        },
        (respon) => {
          that.craftNo = respon.loomNo;
          that.craftId = respon.craftId;
          that.width = respon.width;
          that.referenceMiWeight = respon.referenceMiWeight;    //从坯布刻盘重改为设计坯布米克重
          that.miWeight = respon.miWeight;
          that.designMiWeight = respon.greyClothMiWeightDesign;
          that.resId = respon.id;
          that.designSeqNo = respon.designSeqNo;
          getTaskList(
            {
              resUrl:
                process.env.VUE_APP_YARN_URL +
                that.params.resUrl +
                "/" +
                that.params.stepNo,
            },
            (res) => {
              if (res.items && res.items.length != 0) {
                /*res.items.forEach((item, i) => {
                  let child = [];
                  if (item.label != "长度") {
                    item.originalValue = 0;
                    child.push(item);
                    that.btnArr.push({
                      label: item.label,
                      color:
                        i === 1
                          ? "#07c160"
                          : i === 2
                          ? "#1989fa"
                          : i === 3
                          ? "#7232dd"
                          : i === 4
                          ? "#ee0a24"
                          : i === 5
                          ? "#ff976a"
                          : i === 6
                          ? "rgb(114, 50, 221)"
                          : i === 7
                          ? "#8600FF"
                          : i === 8
                          ? "#D200D2"
                          : i === 9
                          ? "#F00078"
                          : i === 10
                          ? "#00CACA"
                          : i === 11
                          ? "#0066CC"
                          : i === 12
                          ? "#5CADAD"
                          : i === 13
                          ? "#949449"
                          : i === 14
                          ? "#FFAF60"
                          : i === 15
                          ? "#737300"
                          : "#737300",
                      originalValue: 0,
                      value: 0,
                    });
                  }
                  if (child.length > 0) {
                    that.items.push(child);
                  }
                });*/
              }

              that.defaultData = deepCopy(that.items);
              if (getTableData()) {
                that.tableData = getTableData();
              } else {
                let params = {
                  no: "",
                  label: "",
                  workerId: "",
                  originalValue: "",
                  greyClothId: that.params.resId,
                  items: that.items,
                };
                that.tableData.push(params);
              }
            }
          );
        }
      );
    },
    // 重新连接设备
    onClickReconnection() {
      this.$refs.tabDiv.focus();
      this.syncClientsInfo();
      this.syncServersInfo();
    },
    // 解码
    decodeUnicode(str) {
      str = str.replace(/\\/g, "%");
      //转换中文
      str = unescape(str);
      //将其他受影响的转换回原来
      str = str.replace(/%/g, "\\");
      //对网址的链接进行处理
      str = str.replace(/\\/g, "");
      return str;
    },
    // 重新获取
    onClickGetTable(index) {
      this.currIndex = index;
      this.obtainStatus = false;
      // 获取跑码机数据
      this.sendDataSPP(this.checkHexStr("01 03 00 21 00 02 94 01"));
      this.$refs.tabDiv.focus();
    },
    // 删除
    onDelete(index) {
      const that = this;
      that.$refs.tabDiv.focus();
      if (that.tableData.length != 1 && that.tableData[index].originalValue != "") {
        const worker = this.tableData.splice(index, 1)[0];
        that.currIndex = this.tableData.length - 1;
        that.obtainStatus = false;

        //移除疵点
        that.flaw.data.filter(tag => tag.workerId == worker.workerId).forEach(tag => {
          that.delFlawFn(tag);
        });
      }
    },
    addSuccessLog(name, msg) {
      this.$toast({
        type: "success",
        message: name + msg,
        duration: 1000,
      });
    },
    addErrorLog(name, code, msg) {
      this.$toast({
        type: "fail",
        message: name + code + msg,
        duration: 1000,
      });
    },
    // 节流 3s 操作一次
    userClickBtn() {
      let that = this;
      let len = 0;
      that.scanStatus = false;
      // 设置定时器
      let timer;
      // 设置现在的时间
      let now = dayjs().valueOf();
      // 当现在的时间减去上次点击的时间小于5s时,给出提示，并结束执行函数
      if (that.lastClickTime && now - that.lastClickTime < 5000) {
        clearTimeout(timer);
        this.$toast({
          message: "操作频率太快，请勿重复操作！",
          type: "fail",
        });
        return;
      } else {
        // 若大于5s，则把现在的时间赋值个lastTime
        that.lastClickTime = now;
      }
      timer = setTimeout(function () {
        that.tableData.forEach((item) => {
          if (!item.originalValue) {
            len++;
          }
        });
        if (len > 1) {
          that.$toast.fail("请核对长度");
          return false;
        }
        if(that.currWeight > 0) {
          that.scanStatus = true;
          that.$toast({
            type: "success",
            message: "重量已清零",
            onClose: () => {
              setWeight(0);
              setErrorWeight(0);
            },
          });
        } else {
          that.onGetWeight();
        }
        // 每次点击按钮都要把最新的时间赋值给lastTime
        that.lastClickTime = dayjs().valueOf();
      }, 200);
    },
    //  获取下一步信息
    onGetNextInfo(passFlag) {
      const that = this;

      if(!passFlag) {   //说明是确认扫码通过
        let curMiWeight = getFloat(that.currWeight * 1000 / that.totalLength, 1);
        if((that.referenceMiWeight - curMiWeight) > that.errorMiWeight || (curMiWeight - that.referenceMiWeight) > that.errorMiWeight) {
          //播放音频
          let errMiWeightWarnAudio = that.$refs.errMiWeightWarnAudio;
          errMiWeightWarnAudio.play();

          that.scanOpt = 2;
          that.scanWorkerSub(that);
          return;
        }
      }

      that.sendDataSPP(that.checkHexStr("01 06 00 00 00 02 08 0B"));
      if (that.printStatus) {
        // 打印
        getTaskStep(
          {
            resUrl:
              process.env.VUE_APP_YARN_URL +
              that.params.doingResUrl +
              "/" +
              that.params.taskId,
          },
          (doingUrl) => {
            let str = SPLIT_BLANK;
            if(that.flaw.data.length > 0) {
              str = that.flaw.data.map(flaw => flaw.flaw + SPLIT_COLON + flaw.pos).join(SPLIT_SPACE);
            }
            doingUrl.str = str;
            that.getConnectState(doingUrl, true);
          }
        );
      } else {
        that.currIndex = that.tableData.length - 1;
        if (
          that.tableData[that.currIndex].no === "" ||
          that.tableData[that.currIndex].originalValue === "" ||
          that.tableData[that.currIndex].originalValue === 0
        ) {
          if (that.currIndex === 0) {
            return false;
          }
        }
        that.nextStepData = [];
        that.nextStepAllData = []; // // 获取下一步信息
        getNextInfo(
          {
            flowType: that.params.flowType,
            stepNo: that.params.stepNo,
          },
          function (res) {
            console.log(res, "提交前一步");
            that.nextStepAllData = res;
            // 胚布流程
            that.params.nextStepNo.split(",").forEach((item, i) => {
              that.nextStepData.push(
                item.split("_")[0] + "@0:" + res[i].depId + "_" + res[i].postId
              );
            });
            that.onGetNextCommit();
          }
        );
      }
    },
    // 提交
    onGetNextCommit() {
      const that = this;
      let resParams = {
        stepId: that.params.stepId,
        stepNo: that.params.stepNo,
        stepName: that.params.stepName,
        items: [],
        length: that.totalLength,
        weight: that.currWeight,
        width: that.width
      };
      that.newArr = deepCopy(that.tableData);
      that.newArr.splice(that.newArr.length - 1, 1);
      that.newArr.forEach((item, i) => {
        let resultArr = [];
        if (item.items.length != 0) {
          resultArr = item.items.reduce(function (a, b) {
            return a.concat(b);
          });
        }
        that.newArr[i].items = resultArr;
      });
      let obj = {
        opt: 4,
        label: "默认",
        value: JSON.stringify(that.newArr),
      };
      resParams.items.push(obj);
      getNextCommit(
        {
          taskId: that.params.taskId,
          stepNo: that.params.stepNo,
          nextStepIndex: that.nextStepData.join(","),
          loopCount: "1",
          resId: that.resId,
          resParams: JSON.stringify(resParams),
          flaws: that.flaw.data.length > 0 ? JSON.stringify(that.flaw.data) : SPLIT_BLANK
        },
        function () {
          that.$toast({
            type: "success",
            message: "确认成功，下一步" + that.params.nextStepName,
            duration: 1000,
            onClose: () => {
              setWeight(that.weight);
              removeTableData();
              that.printStatus = true;
              // 连接打印机 绣字
              getTaskStep(
                {
                  resUrl:
                    process.env.VUE_APP_YARN_URL +
                    that.params.doingResUrl +
                    "/" +
                    that.params.taskId,
                },
                (doingUrl) => {
                  let str = SPLIT_BLANK;
                  if(that.flaw.data.length > 0) {
                    str = that.flaw.data.map(flaw => flaw.flaw + SPLIT_COLON + flaw.pos).join(SPLIT_SPACE);
                  }
                  doingUrl.str = str;
                  // 连接打印
                  that.getConnectState(doingUrl, true);
                }
              );
            },
          });
        }
      );
    },
    // 查询打印机连接状态
    getConnectState(data, status) {
      const that = this;
      that.$toast({
        type: "loading",
        message: "查询打印机连接状态",
      });
      var obj = window.api.require("xGprinterPlus");
      var ret = obj.getConnectState();
      if (ret.status) {
        let result = false;
        ret.state.forEach((bool) => {
          if (bool) {
            result = bool;
          }
        });
        if (result) {
          // 已连接  获取打印数据打印
          that.onPrintLabel(data);
        } else {
          // 未连接
          that.$toast({
            type: "error",
            message: "未连接, 请等待",
            duration: 1500,
            onClose: () => {
              that.connectBleByMacAddress(data, status);
            },
          });
        }
      } else {
        // 未连接
        that.$toast({
          type: "error",
          message: "未连接, 请等待",
          duration: 1500,
          onClose: () => {
            that.connectBleByMacAddress(data, status);
          },
        });
      }
    },
    // mac 地址连接
    connectBleByMacAddress(data, status) {
      const that = this;
      if (status) {
        that.$toast({
          type: "loading",
          message: "正在连接，请稍后",
          duration: 20000,
        });
      }

      let demo = window.api.require("xGprinterPlus");
      demo.connectBleByMacAddress({
        macAddress: that.printMac
      }, (ret, err) => {
        if (ret.status) {
          if (ret.message === "已连接") {
            that.$toast.clear();
            // 绣字打印
            if (status) {
              that.onPrintLabel(data);
            }
          } else if (ret.message === "连接失败") {
            that.$toast.clear();
            that.$toast.fail("连接失败");
          }
        } else {
          that.$toast.clear();
          that.$toast.fail(err.msg);
        }
      });
    },
    // 绣字前打印
    onPrintLabel(data) {
      const that = this;
      let y1 = [
        that.pos.y,
        that.pos.y + 200,
        that.pos.y + 600,
        that.pos.y + 900,
      ];
      let demo = window.api.require("xGprinterPlus");
      let rows = [
        {
          lineType: "size",
          width: 30,
          height: 160,
        },
        {
          lineType: "gap",
          data: 2,
        },
        {
          lineType: "direction", //设置打印方向
          direction: "forward", //backward|forward
          mirror: "normal", //normal|mirror
        },
        {
          lineType: "cls", // 清除打印缓冲区
        },
        {
          lineType: "text", //绘制简体中文
          x: that.pos.x,
          y: y1[0],
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: "经轴编号：" + data.craftNo,
        },
        {
          lineType: "text", //绘制简体中文
          x: that.pos.x,
          y: y1[1],
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: "工艺品名：" + data.designNo,
        },
        {
          lineType: "text", //绘制简体中文
          x: that.pos.x,
          y: y1[2] + 200,
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: "色号：" + data.colorNo,
        },
        {
          lineType: "text", //绘制简体中文
          x: that.pos.x,
          y: y1[3] + 150,
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: "批号：" + data.lotNo,
        },

        {
          lineType: "text", //绘制简体中文
          x: that.pos.x - 35,
          y: that.pos.y,
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: "匹号：" + data.designSeqNo,
        },
        {
          lineType: "text", //绘制简体中文
          x: that.pos.x - 35,
          y: that.pos.y + 300,
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: "织机号: " + data.loomNo,
        },
        {
          lineType: "text", //绘制简体中文
          x: that.pos.x - 35,
          y: that.pos.y + 600,
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: "落布人：" + data.receiverName,
        },
        {
          lineType: "text", //绘制简体中文
          x: that.pos.x - 35,
          y: that.pos.y + 900,
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: "落布日期：" + dayjs(data.receiveAt).format("YYYY-MM-DD HH:mm"),
        },

        {
          lineType: "text", //绘制简体中文
          x: that.pos.x - 85,
          y: that.pos.y,
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: "下机门幅: " + data.width,
        },
        {
          lineType: "text", //绘制简体中文
          x: that.pos.x - 85,
          y: that.pos.y + 190,
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: "坯布长: " + data.length,
        },
        {
          lineType: "text", //绘制简体中文
          x: that.pos.x - 85,
          y: that.pos.y + 380,
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: "坯布重: " + data.weight,
        },
        {
          lineType: "text", //绘制简体中文
          x: that.pos.x - 85,
          y: that.pos.y + 570,
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data:
            "米克重: " +
            parseInt((Number(data.weight) / Number(data.length)) * 1000),
        },
        {
          lineType: "text", //绘制简体中文
          x: that.pos.x - 85,
          y: that.pos.y + 760,
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: "纬密: " + data.latDensity,
        },
        {
          lineType: "text", //绘制简体中文
          x: that.pos.x - 85,
          y: that.pos.y + 950,
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: "检验人: " + data.inspectorName,
        }, {
          lineType: "text", //绘制简体中文
          x: that.pos.x - 85,
          y: that.pos.y + 1140,
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: "预计坯布",
        }, {
          lineType: "text", //绘制简体中文
          x: that.pos.x - 135,
          y: that.pos.y,
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: "预计成品克重: " + data.miWeightDesign,
        }, {
          lineType: "text", //绘制简体中文
          x: that.pos.x - 135,
          y: that.pos.y + 240,
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: "刻盘克重: " + data.miWeight,
        }, {
          lineType: "text", //绘制简体中文
          x: that.pos.x - 135,
          y: that.pos.y + 460,
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: "成份含量: " + data.productComposition.replace(/ /g, ""),
        }, {
          lineType: "text", //绘制简体中文
          x: that.pos.x - 135,
          y: that.pos.y + 910,
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: "入库绣字: " + data.embroideryNo,
        }, {
          lineType: "text", //绘制简体中文
          x: that.pos.x - 185,
          y: that.pos.y,
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: data.str,
        },
      ];
      if (data.str2) {
        rows.push({
          lineType: "text", //绘制简体中文
          x: that.pos.x - 235,
          y: that.pos.y,
          rotation: 90, // 0|90|180|270
          xscal: 1, //1~10
          yscal: 1, //1~10
          data: data.str2,
        });
      }
      demo.printLabel(
        {
          rows: rows,
        },
        function (ret, err) {
          if (ret.status) {
            that.$toast({
              type: "success",
              message: "打印成功",
              onClose: () => {
                window.api.closeToWin({ name: "checkCloth" });
                // 跳转首页
                openWin("index");
              },
            });
          } else {
            that.getConnectState(data);
            that.$toast.fail("打印异常" + err.msg);
          }
        }
      );
    },
    // 加法
    onAddition(num1, num2) {
      var r1, r2, m;
      try {
        r1 = num1.toString().split(".")[1].length;
      } catch (e) {
        r1 = 0;
      }
      try {
        r2 = num2.toString().split(".")[1].length;
      } catch (e) {
        r2 = 0;
      }
      m = Math.pow(10, Math.max(r1, r2));
      return Math.round(num1 * m + num2 * m) / m;
    },
    // 断开连接
    disconnect() {
      window.api.require("cxgBluetoothClient").disconnect(
        {
          address: this.metreMac || "C4:4C:13:16:74:D9",
          UUID: this.serveUUID,
        },
        function (ret, err) {
          if (!err) {
            console.log("断开连接成功");
          } else {
            alert("code: " + err.code + " msg: " + err.msg);
          }
        }
      );
    },

    // 判断是否已开启蓝牙
    isEnabledBluetooth() {
      window.api;
      const that = this;
      window.api
        .require("cxgBluetoothBase")
        .isEnabledBluetooth({}, (ret, err) => {
          if (!err) {
            if (ret.state) {
              that.connect();
            }
          } else {
            that.addErrorLog("isEnabledBluetooth", err.code, err.msg);
          }
        });
    },
    // 同步数据
    syncClientsInfo() {
      const that = this;
      window.api
        .require("cxgBluetoothClient")
        .syncClientsInfo({}, (ret, err) => {
          if (!err) {
            that.addSuccessLog("syncClientsInfo", "同步数据成功");
          } else {
            that.addErrorLog("syncClientsInfo", err.code, err.msg);
          }
        });
    },
    // 服务端
    syncServersInfo() {
      const that = this;
      window.api
        .require("cxgBluetoothServer")
        .syncServersInfo({}, (ret, err) => {
          if (!err) {
            that.isEnabledBluetooth();
            that.addSuccessLog("syncServerInfo", "服务信息同步成功!");
          } else {
            that.addErrorLog("syncServerInfo", err.code, err.msg);
          }
        });
    },
    // 连接设备
    connect() {
      const that = this;
      that.$toast.loading({
        message: "连接设备中",
        forbidClick: true,
        duration: 20000,
        loadingType: "spinner",
      });
      window.api.require("cxgBluetoothClient").connect(
        {
          address: that.metreMac || "C4:4C:13:16:74:D9",
          UUID: that.serveUUID,
        },
        function (ret, err) {
          //多次返回
          that.$toast.clear();
          if (!err) {
            if (ret.data === true) {
              that.$toast({
                type: "success",
                message: "连接成功",
                duration: 1000,
                onClose: () => {
                  that.setReadDataCallbackSPP();
                },
              });
            }
            //设备断开
            if (ret.data.disconnectAddress) {
              alert("断开连接成功");
            }
          } else {
            if (err.code == 5) {
              that.$toast({
                type: "success",
                message: "连接成功",
                duration: 1000,
                onClose: () => {
                  that.setReadDataCallbackSPP();
                },
              });
            } else {
              that.addErrorLog("connect", err.code, err.msg);
              // that.connect();
            }
          }
        }
      );
    },
    // 发送数据
    setReadDataCallbackSPP() {
      const that = this;
      window.api.require("cxgBluetoothClient").setReadDataCallback(
        {
          address: that.metreMac || "C4:4C:13:16:74:D9",
          UUID: that.serveUUID,
          bufferSize: 1024,
          isReturnHex: true,
          isNoReturnData: false,
        },
        (ret, err) => {
          if (!err) {
            if (ret.data === true) {
              // that.sendDataSPP(that.checkHexStr("01 03 00 21 00 02 94 01"));
              that.$toast({
                type: "success",
                message: "设置成功",
                duration: 1000,
              });
              return;
            }

            let res = ret.data.trim();
            that.SPPClientArr.push(res.split(" "));
            let resultArr = [];
            if (that.SPPClientArr.length !== 0) {
              resultArr = that.SPPClientArr.reduce(function (a, b) {
                return a.concat(b);
              });
            }
            if (resultArr.length == 9) {
              this.obtainStatus = false;
              if (resultArr[4] == "ff") {
                that.$toast.fail("异常，长度为负值");
                setTimeout(() => {
                  that.sendDataSPP(that.checkHexStr("01 06 00 00 00 02 08 0B"));
                  // that.tableData[that.tableData.length - 1].no = "";
                  that.loading = false;
                }, 1000);
              } else {
                that.length =
                  parseInt("0x" + resultArr[4] + resultArr[5] + resultArr[6]) /
                  100;
                if (that.length) {
                  if (!that.otherLenFlag) {
                    if (that.tableData[that.currIndex].no !== "") {
                      that.tableData[that.currIndex].originalValue = getFloat(
                        that.length,
                        1
                      );
                      that.loading = false;
                      that.sendDataSPP(
                        that.checkHexStr("01 06 00 00 00 02 08 0B")
                      );
                      that.items = deepCopy(that.defaultData);
                      let params = {
                        no: "",
                        label: "",
                        workerId: "",
                        originalValue: "",
                        greyClothId: that.params.resId,
                        items: that.items,
                      };
                      that.tableData.push(params);
                      that.currIndex = that.tableData.length - 1;
                      that.otherLenFlag = false;
                    }
                  } else {
                    if(that.length > 0) {
                      const lastWorker = that.tableData[that.tableData.length - 1];
                      that.flaw.data.push({
                        workerId: lastWorker.workerId,
                        worker: lastWorker.no,
                        flaw: that.flaw.curBtn.text,
                        pos: (that.tableData.map(w => Number(w.originalValue)).reduce((a, b) => a+b) + that.length).toFixed(1),
                      });
                      //设置到本地缓存
                      storage.set("flawData", that.flaw);

                      that.$forceUpdate();
                      that.$refs.tabDiv.focus();
                      that.otherLenFlag = false;
                    }
                  }
                }
              }
            }
          } else {
            that.$toast({
              type: "fail",
              message: err.msg,
              duration: 1000,
              onClose: () => {
                if (err.code === 11 || err.code === 22) {
                  that.connect();
                } else {
                  that.setReadDataCallbackSPP();
                }
              },
            });
          }
        }
      );
    },
    sendDataSPP(dataStr) {
      const that = this;
      that.obtainStatus = false;
      that.SPPClientArr = [];
      window.api.require("cxgBluetoothClient").sendData(
        {
          data: dataStr,
          isHex: true,
          address: that.metreMac || "C4:4C:13:16:74:D9",
          UUID: that.serveUUID,
        },
        (ret, err) => {
          if (!err) {
            that.obtainStatus = true;
            if(!that.otherLenFlag) {
              that.addSuccessLog("sendDataSPP", "计米器已归零");
            }
          } else {
            that.addErrorLog("sendDataSPP", err.code, err.msg);
          }
        }
      );
    },
    // 手动清零计米器
    onClickSetRice() {
      this.$refs.tabDiv.focus();
      this.sendDataSPP(this.checkHexStr("01 06 00 00 00 02 08 0B"));
    },
    checkHexStr(dataStr) {
      dataStr = dataStr.replace(/\s/g, "");
      if (dataStr.length % 2 != 0) {
        return "";
      }
      if (/[0-9A-Fa-f]/g.test(dataStr)) {
        return dataStr;
      }
      return "";
    },
    // 监听扫码时间
    onWatchEnter() {
      this.code = "";
      this.lastTime = "";
      this.nextTime = "";
      this.lastCode = "";
      this.nextCode = "";
      window.addEventListener("keydown", this.onClickKeydown);
    },
    // 监听事件
    onClickKeydown(e) {
      const that = this;
      that.loading = true;
      that.$toast.clear();
      if (window.event) {
        // IE
        that.nextCode = e.keyCode;
      } else if (e.which) {
        // Netscape/Firefox/Opera
        that.nextCode = e.which;
      }
      if (e.which === 13) {
        if (that.code.length < 3) return; // 手动输入的时间不会让code的长度大于2，所以这里只会对扫码枪有
        console.log(that.code.replace(/Shift/g, ""));
        let value = that.code.replace(/Shift/g, "");
        if (!that.scanStatus) {
          let scanTime = getScanTime() ? getScanTime() : 0;
          if (scanTime == 0 || dayjs().valueOf() - scanTime > 3000) {
            if(that.scanOpt > 0 && !that.isJSON(value).workerId) {    //是改米克重的 扫的不是小码
              let optTmp = that.scanOpt;
              that.scanOpt = 0;   //重置改米克重标记

              let infos = value.split(",type=login,");
              getLogin({
                no: infos[0],
                pwd: infos[1],
                platform: 2,
                captcha: randomStr(),
              }, res => {
                if(res.permission.indexOf("050602") >= 0) {     //更改克重,强制通过权限 后端配置
                  let params = {};
                  params.isTokenFlag = true;
                  params.accessToken = res.accessToken;
                  params.userId = res.userId;
                  params.craftId = that.craftId;
                  params.miWeight = that.changedMiWeight;
                  if(optTmp == 1) {
                    changeMarkMiWeight(params, () => {
                      that.referenceMiWeight = that.changedMiWeight;
                      that.$toast.success("操作成功");
                    });
                  } else if(optTmp == 2) {
                    that.onGetNextInfo(true);
                  } else {
                    that.$toast.fail("未知的扫码操作");
                  }
                } else {
                  that.$toast.fail("没有权限");
                }
              });
            } else if (that.tableData[that.tableData.length - 1].no == "") {
              // 获取到扫码枪输入的内容，其它操作
              let obj = that.isJSON(value);
              if(!obj.workerId)  {
                that.$toast.fail("请扫员工小码");
                return;
              }
              // 获取扫码用户信息
              getWorkerInfo(obj.workerId, (res) => {
                that.tableData[that.tableData.length - 1].no =
                  res.no + " " + res.realName;
                that.tableData[that.tableData.length - 1].workerId =
                  obj.workerId;
                setScanTime(dayjs().valueOf());

                // that.$toast({
                //   type: "loading",
                //   message: "获取长度中",
                //   duration: 1000,
                //   onClose: () => {
                //     // 获取跑码机数据
                //     if (that.tableData[that.tableData.length - 1].no !== "") {
                //       that.sendDataSPP(
                //         that.checkHexStr("01 03 00 21 00 02 94 01")
                //       );
                //     }
                //   },
                // });
              });
            } else if (
              that.tableData[that.tableData.length - 1].originalValue == ""
            ) {
              // 获取到扫码枪输入的内容，其它操作
              let obj = that.isJSON(value);
              if(!obj.workerId)  {
                that.$toast.fail("请扫员工小码");
                return;
              }
              // 获取扫码用户信息
              getWorkerInfo(obj.workerId, () => {
                // that.tableData[that.tableData.length - 1].no =
                //   res.no + " " + res.realName;
                // that.tableData[that.tableData.length - 1].workerId = obj.workerId;
                if (
                  obj.workerId ===
                  that.tableData[that.tableData.length - 1].workerId
                ) {
                  that.$toast({
                    type: "loading",
                    message: "获取长度中",
                    duration: 1000,
                    onClose: () => {
                      // 获取跑码机数据
                      if (that.tableData[that.tableData.length - 1].no !== "") {
                        that.sendDataSPP(
                          that.checkHexStr("01 03 00 21 00 02 94 01")
                        );
                      }
                    },
                  });
                } else {
                  that.$toast({
                    type: "fail",
                    message: "两次扫码不相符",
                    duration: 1500,
                  });
                }
              });
            }
          }
        } else {
          // 称重
          // that.onGetWeight(true);
        }
        that.code = "";
        that.lastCode = "";
        that.lastTime = "";
        return;
      }
      that.nextTime = new Date().getTime();
      if (!that.lastTime && !that.lastCode) {
        console.log("扫码开始。。。");
        that.code += e.key;
      }
      if (
        that.lastCode &&
        that.lastTime &&
        that.nextTime - that.lastTime > 500
      ) {
        // 当扫码前有keypress事件时,防止首字缺失
        console.log("防止首字缺失。。。");
        that.code = e.key;
      } else if (that.lastCode && that.lastTime) {
        that.code += e.key;
      }
      that.lastCode = that.nextCode;
      that.lastTime = that.nextTime;
    },
    // 点击 == 扫码功能
    onClickScanBtn(btn) {
      const that = this;
      that.$refs.tabDiv.focus();
      let scanTime = getScanTime() ? getScanTime() : 0;
      that.currIndex = that.tableData.length - 1;
      if (scanTime == 0 || dayjs().valueOf() - scanTime > 3000) {
        if (that.tableData[that.tableData.length - 1].no == "") {
          // 获取扫码用户信息
          getWorkerInfo(btn.id, (res) => {
            that.tableData[that.tableData.length - 1].no =
              res.no + " " + res.realName;
            that.tableData[that.tableData.length - 1].workerId = btn.id;
            setScanTime(dayjs().valueOf());
          });
        } else if (
          that.tableData[that.tableData.length - 1].originalValue == ""
        ) {
          // 获取扫码用户信息
          getWorkerInfo(btn.id, () => {
            if (btn.id === that.tableData[that.tableData.length - 1].workerId) {
              that.$toast({
                type: "loading",
                message: "获取长度中",
                duration: 1000,
                onClose: () => {
                  // 获取跑码机数据
                  if (that.tableData[that.tableData.length - 1].no !== "") {
                    that.sendDataSPP(
                      that.checkHexStr("01 03 00 21 00 02 94 01")
                    );
                  }
                },
              });
            } else {
              that.$toast({
                type: "fail",
                message: "两次扫码不相符",
                duration: 1500,
              });
            }
          });
        }
      }
    },
    isJSON(str) {
      let obj = "";
      if (typeof str == "string") {
        try {
          obj = JSON.parse(str);
          return obj;
        } catch (e) {
          return false;
        }
      }
      return obj;
    },
    // 获取重量
    onGetWeight() {
      const that = this;
      // 重新打印 重量已存在
      that.$toast.loading({
        message: "获取称重中",
        forbidClick: true,
        duration: 1000,
        loadingType: "spinner",
      });
      var serial = window.api.require("serialPort");
      serial.examine(function (ret) {
        if (ret.code) {
          serial.openRead(
            {
              com: "/dev/ttyS3", //串口地址
              rate: 9600, //波特率
              delay: 500, //RX延时 此参数能让数据返回完整单位毫秒（具体设置大小自测）
              hex: false, //返回数据类型 false:text  true:hex
            },
            function (ret) {
              console.log(ret);
              if (ret.code && ret.data) {
                let respon = ret.data.replace(/\n\r/g, " ");
                serial.close(function (ret) {
                  that.$toast.clear();
                  let res = respon.split("=");
                  let resultWeight = [...new Set(res)].filter(
                    (item) => item !== ""
                  )[0];
                  console.log(resultWeight, "resultWeight");
                  // 关闭协议成功

                  that.totalWeight = getWeight() ? getWeight() : 0;
                  console.log(that.totalWeight, "totalWeight");

                  let weight = that.reverse_a_number(resultWeight).replace(/\b(0+)/gi, "");
                  console.log(weight, "weight");

                  let errorWeight = getErrorWeight() ? getErrorWeight() : 0;
                  // 称重异常  根据米克重自动计算
                  if (
                    parseInt(weight) <= 0 ||
                    parseInt(weight) <= parseInt(that.totalWeight)
                  ) {
                    if (that.currWeight) {
                      that.scanStatus = true;
                      return false;
                    }
                    that.$toast.fail("称重异常，请重新获取/手动输入");
                    return false;
                  } else {
                    that.weight = weight;
                    // 若重量存在 => 手动输入
                    if (that.currWeight > 10) {
                      errorWeight = getFloat(
                        2 * (that.currWeight / that.totalLength),
                        2
                      );
                      console.log(errorWeight, "误差重量");
                      setErrorWeight(errorWeight);
                      that.scanStatus = true;
                    } else {
                      let oldWeight = Math.abs(
                        Number(weight) - Number(that.totalWeight) - errorWeight
                      );
                      console.log(oldWeight, "重量");

                      let errorLen = Number(that.totalLength) - 2;

                      errorWeight = getFloat(2 * (oldWeight / errorLen), 2);
                      console.log(errorWeight, "误差重量");

                      that.currWeight = getFloat(
                        Number(oldWeight) + Number(errorWeight),
                        1
                      );
                      console.log(that.currWeight, "实际重量");

                      setErrorWeight(errorWeight);

                      that.scanStatus = true;
                    }
                  }

                  if (ret.code) {
                    // 关闭
                    console.log("关闭协议");
                  }
                });
              }
            }
          );
        } else {
          that.$toast.clear();
          that.$toast.fail("协议打开失败，请手动填写重量");
        }
      });
    },
    // 反转数字
    reverse_a_number(n) {
      n = n + "";
      return n.split("").reverse().join("");
    },
    // 数据异常  手动输入长度时
    onClickInput(val) {
      if (val && this.tableData[this.tableData.length - 1].no !== "") {
        this.items = deepCopy(this.defaultData);
        let params = {
          no: "",
          label: "",
          workerId: "",
          originalValue: "",
          greyClothId: this.params.resId,
          items: this.items,
        };
        this.tableData.push(params);
        this.currIndex = this.tableData.length - 1;
        this.otherLenFlag = false;
      }
    },
    // 获取挡车工列表
    onGetLoginList() {
      this.loginBtn = [];
      const that = this;
      getClothList(
        {
          postId: 231,
        },
        function (res) {
          that.loginBtn = res;
        }
      );
    },

    //扫码更改克重参考值
    scan4ChangeMiWeightFn() {
      let that = this;

      if(!/^[1-9]+\d*\.\d+$/.test(that.changedMiWeight) && !/^[1-9]+\d*$/.test(that.changedMiWeight)) {
        that.$toast.fail("请输入正确的数字");
        return;
      }

      that.scanOpt = 1;
      that.scanWorkerSub(that);
    },

    scanWorkerSub(that) {
      //这里存在toast被其他地方(如设备连接) 更改的情况,所以需要定时器重置标记. onClose里不能重置标记,因为在扫码响应里是先关闭toast
      if(that.scan4ChangeMiWeightTimer) {
        clearTimeout(that.scan4ChangeMiWeightTimer);
      }
      that.scan4ChangeMiWeightTimer = setTimeout(() => {
        that.scanOpt = 0;
      }, 14500);
      that.$toast({
        type: "loading",
        message: "请扫工艺组长二维码",
        forbidClick: true,
        duration: 15000,
      });
    },

    /* 初始化 */
    init() {
      const that = this;
      that.params = window.api.pageParam;
      that.onGetInit();
      that.onGetLoginList();
      that.onGetTableData();
      that.onWatchEnter();
      // 获取重量
      // that.onGetWeight(false);
      // that.connectBleByMacAddress("", false);

      //加载疵点配置
      that.flaw.taskId = that.params.taskId;
      loadFlawConfigData({
        type: 1
      }, data => {
        data.forEach(flaw => {
          that.flaw.btnArr.push({
            text: flaw,
            color: randomColor(1),
          });
        });

        //加载疵点数据
        const flawData = storage.get("flawData");
        if(flawData) {
          if(flawData.taskId != that.params.taskId) {
            storage.remove("flawData");
          } else {
            flawData.data.forEach(flaw => {
              that.flaw.data.push(flaw);
            });
            that.flaw.btnArr.sort((a, b) => {
              if(that.flaw.data.some(f => f.flaw == a.text)) {
                return -1;
              } else if(that.flaw.data.some(f => f.flaw == b.text)) {
                return 1;
              } else {
                return 0;
              }
            });
          }
        }
      });

      // 监听页面消失的时候，关掉页面就可以了
      window.api.addEventListener({
        name: "viewdisappear",
      }, () => {
        window.removeEventListener("keydown", that.onClickKeydown);
        removeScanTime();
        window.api.closeWin();
      });
    },

    /* 增加疵点 */
    addFlawFn(btn) {
      const that = this;
      const lastWorker = that.tableData[that.tableData.length - 1];
      if(!lastWorker || lastWorker.workerId == SPLIT_BLANK) {
        that.$toast.fail("请先选择员工");
        return;
      }
      that.flaw.curBtn = btn;
      if (!that.otherLenFlag) {
        that.otherLenFlag = true;
      }
      that.sendDataSPP(that.checkHexStr("01 03 00 21 00 02 94 01"));
    },

    /* 删除疵点 */
    delFlawFn(tag) {
      const that = this;
      const tIndex = that.flaw.data.findIndex(t => t == tag);
      if(tIndex != -1) {
        that.flaw.data.splice(tIndex, 1);
        if(that.flaw.data.length > 0) {
          storage.set("flawData", that.flaw);
        } else {
          storage.remove("flawData");
        }
      }
    }
  },
};
</script>

<style lang="scss">
.checkCloth {
  .checkCloth——nav {
    display: flex;
    .van-nav-bar {
      flex: 0 0 75%;
      .van-nav-bar__left {
        .van-button {
          margin-right: 30px;
          .van-icon-arrow-left {
            line-height: 42px !important;
            &::before {
              font-size: 20px !important;
              color: #fff;
            }
          }
        }
      }
    }
    .checkCloth——nav_weight {
      display: flex;
      flex-wrap: nowrap;
      justify-content: flex-end;
      flex: 1;
      line-height: 85px;
      font-size: 26px;
      text-align: right;
      padding-right: 20px;
      span {
        display: flex;
        flex: 1;
        justify-content: flex-end;
      }
      .van-cell {
        flex: 0 0 100px;
        .van-cell__value {
          display: flex;
          align-items: center;
          .van-field__control {
            font-size: 26px;
            line-height: 60px;
          }
        }
      }
    }
  }
  // 滚动高度
  .checkCloth-wrapper {
    height: calc(100% - 88px);
    display: flex;
    & > div {
      flex: 1;
      &.checkCloth-wrapper__left {
        padding: 0 10px;
        background: #fff;
        .checkCloth-wrapper__right-btn {
          display: flex;
          flex-wrap: wrap;
          width: 70%;
          .van-button {
            width: 120px;
            height: 60px;
            margin-top: 15px;
            font-size: 22px;
            margin-right: 15px;
          }
        }
      }
      &:last-child {
        flex: 0 0 25%;
        border-left: 1px solid #ddd;
      }
      &.checkCloth-wrapper__right {
        padding: 0 20px 20px;
        & > .van-cell {
          margin-bottom: 10px;
          padding: 0 16px;
          .van-cell__title {
            display: flex;
            flex: 0 0 90px;
            align-items: center;
            justify-content: flex-end;
            span {
              font-size: 18px;
            }
          }
          .van-field__control {
            font-size: 18px;
          }
        }

        .public-scroll {
          height: calc(100% - 180px);
          overflow: hidden;
          .checkCloth-wrapper__right-btn {
            display: flex;
            flex-direction: column;
            justify-content: flex-start;
            align-items: center;
            .van-button {
              width: 80%;
              height: 60px;
              margin-bottom: 20px;
              font-size: 30px;
            }
          }
        }
      }
    }
  }
  .public-scroll {
    height: calc(100% - 118px);
    overflow: hidden;
    .van-cell-group {
      .van-cell__title {
        flex: 0 0 72%;
        .van-cell.van-field {
          padding: 0;
          &:not(:last-child)::after {
            border: none;
          }
          .van-field__control {
            height: 30px;
            font-size: 24px;
          }
        }
        span {
          display: flex;
          font-size: 24px;
          line-height: 30px;
        }
        .van-cell__label {
          display: flex;
          flex-direction: column;
          & > div {
            display: flex;
            flex-wrap: wrap;
            p {
              display: flex;
              font-size: 16px;
              width: 150px;
              &.active {
                padding: 5px 0;
                border-bottom: 1px solid #ee0a24;
              }
              span {
                &:nth-child(2) {
                  border-radius: 50%;
                  width: 30px;
                  height: 30px;
                  border: 1px solid sandybrown;
                  justify-content: center;
                  margin: 0 5px;
                  color: sandybrown;
                }
              }
              &:first-child {
                width: 260px;
                span {
                  &:first-child {
                    width: 120px;
                  }
                }
              }
              .van-icon {
                display: flex;
                align-items: center;
                font-size: 26px;
                margin-left: 10px;
                color: #ee0a24;
                position: relative;
                top: 2px;
              }
            }
          }
          .van-checkbox {
            margin-right: 40px;
          }
        }
      }
      .van-cell__value {
        .van-cell {
          padding-top: 0;
          .van-cell__value {
            border: 1px solid #ddd;
            .van-field__body {
              padding-left: 10px;
            }
          }
        }
      }
    }
  }
  .checkCloth-btn {
    width: 700px;
    height: 80px;
    border-radius: 2px;
    margin: 0 auto;
    margin-top: 20px;
    display: flex;
    .van-button {
      flex: 1;
      height: 80px;
      background: #1677ff;
      color: #ffffff;
      font-size: 30px;
    }
  }
}
</style>
